// src/utils/MathUtil.ts

import * as math from 'mathjs'

// 加
export function add(a: number, b: number): number {
    return math.add(a, b)
}

// 减
export function subtract(a: number, b: number): number {
    return math.subtract(a, b)
}

// 乘
export function multiply(a: number, b: number): number {
    return math.multiply(a, b)
}

// 除
export function divide(a: number, b: number): number {
    if (b === 0) {
        throw new Error('除数不能为零')
    }
    return math.divide(a, b)
}

// 表达式
// expression = 1 + 1 * 9
export function evaluate(expression: string): number {
    try {
        return math.evaluate(expression)
    } catch (error) {
        console.error('表达式错误:', error)
        throw error
    }
}
